# %%
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from PIL import Image

img_path = 'IMG_20190926_153556.jpg'  # 图片路径
img = Image.open(img_path)  # 用Image库打开图片
print(img)
img = np.asarray(img)
flip_1 = np.fliplr(img)
plt.imshow(flip_1)
plt.show()
# %%
x = tf.python.read_file(img_path)  # 加载img
x = tf.image.decode_jpeg(x)  # 将img编码返回tensor
flip_2 = tf.image.flip_up_down(x)
plt.imshow(flip_2)
plt.show()
# %%
flip_3 = tf.image.flip_left_right(x)
plt.imshow(flip_3)
plt.show()
# %%
flip_4 = tf.image.random_flip_up_down(x)
plt.imshow(flip_4)
plt.show()
# %%
flip_5 = tf.image.random_flip_left_right(x)
plt.imshow(flip_5)
plt.show()
# %%
